package com.example.barcodeapp.ui.own.activity;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.FragmentAdapter;
import com.example.barcodeapp.base.BaseActivity;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.OnePresenterKeChengXiangQing;
import com.example.barcodeapp.ui.own.fragment.KeChengJieShaoFragment;
import com.example.barcodeapp.ui.own.fragment.KeChengMuLuFragment;
import com.example.barcodeapp.ui.own.fragment.KeChengMuLuZhiBoFragment;
import com.example.barcodeapp.ui.wode.bean.kechengxiangqingBean;
import com.example.barcodeapp.utils.SpUtils;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class XiangQingActivity extends BaseActivity<IOwn.Persenterkechengxiangqing> implements IOwn.Viewkechengxiangqing {


    @BindView(R.id.iv_back_circle)
    ImageView ivBackCircle;
    @BindView(R.id.ff_back_contener)
    FrameLayout ffBackContener;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_location)
    TextView tvLocation;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ll_to_search)
    LinearLayout llToSearch;
    @BindView(R.id.right_iv)
    ImageView rightIv;
    @BindView(R.id.right_iv_two)
    ImageView rightIvTwo;
    @BindView(R.id.tv_rught_)
    TextView tvRught;
    @BindView(R.id.tv_right_two)
    TextView tvRightTwo;
    @BindView(R.id.toolBar)
    Toolbar toolBar;
    @BindView(R.id.banner2)
    Banner banner2;
    @BindView(R.id.tou)
    LinearLayout tou;
    @BindView(R.id.textView16)
    TextView textView16;
    @BindView(R.id.imageView5)
    ImageView imageView5;
    @BindView(R.id.imageView6)
    ImageView imageView6;
    @BindView(R.id.textView17)
    TextView textView17;
    @BindView(R.id.shanchu)
    TextView shanchu;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.xilei_kecheng)
    TextView xileiKecheng;
    @BindView(R.id.textView18)
    TextView textView18;
    @BindView(R.id.constraintLayout2)
    ConstraintLayout constraintLayout2;
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.zhujiaolaoshi)
    ImageView zhujiaolaoshi;
    @BindView(R.id.imageView7)
    ImageView imageView7;
    @BindView(R.id.textView19)
    TextView textView19;
    @BindView(R.id.textView20)
    TextView textView20;
    @BindView(R.id.textView21)
    TextView textView21;
    private ArrayList<Fragment> fragments;
    private FragmentAdapter fragmentAdapter;
    private String u_id;

    @Override
    protected int getLayout() {
        return R.layout.activity_xiang_qing2;
    }

    @Override
    protected void initView() {
        setToolBar(true, false, true, false, false);
        setTitle("课程详情", R.color.black, R.color.white);

        fragments = new ArrayList<>();
        //课程介绍
        fragments.add(new KeChengJieShaoFragment());
        //课程目录 判断是怎样的，系列课，直播课，公开课
        Intent intent = getIntent();
        String data = intent.getStringExtra("data");
        u_id = intent.getStringExtra("u_id");
        if (data.equals("直播课")) {
            fragments.add(new KeChengMuLuFragment());
        } else if (data.equals("系列课程")) {
            fragments.add(new KeChengMuLuZhiBoFragment());
        } else if (data.equals("公开课")) {
            fragments.add(new KeChengMuLuFragment());
        }

        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
        viewpager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(viewpager);
        tabLayout.setTabIconTint(null);//显示图片
        tabLayout.getTabAt(0).setText("课程介绍");
        tabLayout.getTabAt(1).setText("课程目录");
        //支付界面
        textView20.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                addCart();
            }


        });

        //练习班主任界面

        //练习助教老师界面

    }


    private void addCart() {
        String token = SpUtils.getInstance().getString("token");
        Log.e("TAG", "addCart: "+token);
        if(!TextUtils.isEmpty(token)){
//ZhiFuActivity
        }else{
            Toast.makeText(this, "未登录", Toast.LENGTH_SHORT).show();
            Intent instant = new Intent(XiangQingActivity.this, ZhiFuActivity.class);
//            instant.putExtra("data","系列课程");
            startActivity(instant);
        }
    }

    @Override
    protected OnePresenterKeChengXiangQing initPersenter() {
        return new OnePresenterKeChengXiangQing();
    }

    @Override
    protected void initData() {
            persenter.getkechengxiangqing(Integer.parseInt(u_id),2);
    }

    @Override
    public void getkechengxiangqing(kechengxiangqingBean xiLieKeBean) {
//        Glide.with(this).load(xiLieKeBean.getData().getImageurl()).into(banner2);
        ArrayList<String> list = new ArrayList<>();
            list.add(xiLieKeBean.getData().getImageurl());
        banner2.setAdapter(new BannerImageAdapter<String>(list) {
            @Override
            public void onBindView(BannerImageHolder holder, String data, int position, int size) {
                //图片加载自己实现
                Glide.with(holder.itemView)
                        .load(Constants.Base_TPUrl2 + data)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                        .into(holder.imageView);
            }
        });
        textView16.setText(xiLieKeBean.getData().getCoursename());
        textView17.setText(xiLieKeBean.getData().getPrice());
        textView19.setText(xiLieKeBean.getData().getPrice());
        shanchu.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//删除线
        textView21.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//删除线
        xileiKecheng.setText(xiLieKeBean.getData().getKeshi()+"");

    }
}